/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Room;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 *
 * @author mishra
 */
public class EditRoom extends HttpServlet {

    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            Vector<Object> list=new Vector<Object>();
            RoomBean rb=new RoomBean();
            int ava=Integer.parseInt(request.getParameter("Availibi"));
            int nofoBed=Integer.parseInt(request.getParameter("noofBeds"));
            rb.setRoomNo(request.getParameter("roomNo"));
            rb.setFees(Integer.parseInt(request.getParameter("Rent")));
            rb.setHostelId(Integer.parseInt(request.getParameter("hid")));
            list=Room.Query.viewBeds(rb);
            
            out.println("<center><table id='roomBed' style='width: 500px;'><tr><thead style='color: white; background-color: #cc6600;' class='table table-striped dataTable-noheader dataTable-nofooter table-bordered'>");
            out.println("<th><center>Bed Number</center></th>");
            out.println("<th><center>Bed Status</center></th>");
            out.println("<th><center>Action</center></th>");
            out.println("</thead></tr><tbody>");
            if(!list.isEmpty())
            {
            Iterator it=list.iterator();
            while(it.hasNext())
            {
               RoomBean rb1=(RoomBean)it.next();
            int i=1;
            out.println("<tr id='"+rb1.getBedNumber()+"' style='border-bottom: 1px solid #e2e2e2'><td>");
            out.println("<center>"+rb1.getBedNumber()+"</center>");
            out.println("<input type='hidden' name='"+rb1.getBedNumber()+"' value="+rb1.getBedNumber()+" readonly>");
            out.println("</td><td>");
            if(rb1.getBedStatus()==0)
            {
            out.println("<center><span class='label label-success' style='top: -6px;'>Available</span></center>");
            }
            else
            {
             out.println("<center><span class='label label-important' style='top: -6px;'>Not Available</span></center>");
            }
            out.println("</td>");
            out.println("<td>");
            out.println("<center><a href='#'><img alt='edit' title='Delete' class='ico-prev' id='deletebed/"+rb1.getBedNumber()+"' name='deletebed'  onclick='deleteBedsconfirm(this.id)' src='/RIT/img/icons/fugue/cross.png'></a></center>");
            out.println("<input type='hidden' id='delbed"+rb1.getBedNumber()+"' name='delbed' value='"+rb1.getBedNumber()+"--"+rb.getRoomNo()+"--"+rb1.getBedStatus()+"'>");
            out.println("</td></tr>");
            i++;
            }
            }
            else
            {
             out.println("<tr><td colspan='3'>");   
             out.println("<b>No Record Found</b>");
             out.println("</td></tr>");
            }
            out.println("</tbody></table></center>");
            
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(EditRoom.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(EditRoom.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
